package Demo16_30.Test27;

import org.apache.commons.beanutils.BeanUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * Created by 14229 on 2020/1/31.
 */
public class Test {
    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, DocumentException, InstantiationException, ClassNotFoundException {
        SAXReader sr = new SAXReader();
        Document doc = sr. read("bean.xml");
        Element rootElement = doc.getRootElement();
        List<Element> elements = rootElement.elements();

        for (Element element : elements) {
            String className = element.attributeValue("className");
            Class<?> aClass = Class.forName(className);
            Object o = aClass.newInstance();


            List<Element> elements1 = element.elements();
            for (Element element1 : elements1) {
                String name = element1.attributeValue("name");
                String value = element1.attributeValue("value");


                BeanUtils.setProperty(o,name,value);

            }
            System.out.println(o);

        }
    }
}
